var app = getApp(), dataApi = require("../../provider/dataApi.js");

Page({
    data: {
        isData: !0,
        isListData: !1,
        isloading: !0,
        statusBarHeight: "",
        titleBarHeight: "",
        height: "",
        op: "",
        allList: [],
        oneList: [],
        twoList: [],
        threeList: [],
        info: {
            oneIndex: 0,
            twoIndex: 0
        }
    },
    onLoad: function(params) {
        console.log(wx.getSystemInfoSync()), this.setData({
            statusBarHeight: app.globalData.statusBarHeight,
            titleBarHeight: app.globalData.titleBarHeight,
            height: wx.getSystemInfoSync().windowHeight,
            op: app.globalData.op
        }), 1 == params.type && this.setData({
            params: params
        }), console.log(app.globalData.op), this.getSequence();
    },
    getSequence: function() {
        var self = this;
        dataApi.sequence({
            uid: wx.getStorageSync("uid"),
            op: "getallspecial"
        }).then(function(response) {
            console.log(response), self.setData({
                allList: response.data.list,
                isloading: !1
            }), self.handleAllList();
        }).catch(function(error) {
            console.log(error), self.setData({
                isloading: !1
            });
        });
    },
    goBack: function() {
        wx.navigateBack({
            delta: 1
        });
    },
    bindOneChange: function(event) {
        event = +event.detail.value;
        var data = {};
        this.setData((data["info.oneIndex"] = event, data["info.twoIndex"] = 0, data)), this.handleTwoList(event, 0);
    },
    bindTwoChange: function(event) {
        event = +event.detail.value;
        var data = {};
        this.setData((data["info.twoIndex"] = event, data)), this.handleThreeList(event);
    },
    clickThreeItemBtn: function(event) {
        var params = this.data.params;
        app.globalData.lib_id = event.currentTarget.dataset.item.id, params && 1 == params.type ? wx.navigateTo({
            url: "../type-lx/type-lx"
        }) : wx.navigateTo({
            url: "/pages/practice/practice"
        });
    },
    handleAllList: function() {
        var info = this.data.info, allList = this.data.allList;
        if (!(allList.length <= 0)) {
            console.log(allList), allList.forEach(function(item) {
                var isCan = 2;
                item.son && 0 < item.son.length && item.son.forEach(function(subItem) {
                    1 == subItem.is_can && (isCan = 1);
                }), item.isCan = isCan;
            }), (allList = allList.filter(function(item) {
                return 1 == item.isCan;
            })).forEach(function(item) {
                var filteredSon = [];
                0 < item.son.length && item.son.forEach(function(subItem) {
                    1 == subItem.is_can && filteredSon.push(subItem);
                }), item.son = filteredSon;
            }), console.log(allList);
            var hasData = !1;
            0 < allList.length && (hasData = !0), this.setData({
                oneList: allList,
                isListData: hasData
            }), 0 < allList.length && this.handleTwoList(info.oneIndex, info.twoIndex);
        }
    },
    handleTwoList: function(oneIndex, twoIndex) {
        this.setData({
            twoList: this.data.oneList[oneIndex].son
        }), this.handleThreeList(twoIndex);
    },
    handleThreeList: function(twoIndex) {
        var twoList = this.data.twoList, threeList = [], hasData = !1;
        twoList[twoIndex].son && 0 < twoList[twoIndex].son.length && (threeList = this.data.twoList[twoIndex].son, hasData = !0), this.setData({
            threeList: threeList,
            isData: hasData
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});